def a():
    # Write binary data to a file
    with open('somefile.bin', 'wb') as f:
        f.write(b'Hello World')

    # Read the entire file as a single byte string
    with open('somefile.bin', 'rb') as f:
        data = f.read()
        print(data)


def b():
    with open('somefile.bin', 'wb') as f:
        text = 'Hello World'
        f.write(text.encode('utf-8'))

    with open('somefile.bin', 'rb') as f:
        data = f.read(16)
        text = data.decode('utf-8')
        print(text)


def c():
    import array
    nums = array.array('i', [1, 2, 3, 4, 5])
    with open('data.bin', 'wb') as f:
        f.write(nums)

    a = array.array('i',[0, 0, 0, 0, 0, 0, 0, 0])
    with open('data.bin', 'rb') as f:
        f.readinto(a)
    print(a)


if __name__ == '__main__':
    c()
